<template>
	<view>
		<uni-nav-bar :fixed="true" left-icon="back" left-text="返回" right-text="搜索" @clickLeft="leftBack" @clickRight="rightSearch" background-color="#318cff" color="#fff">
			<view class="dfj-bg-white dfj-flex-1 dfj-bd-radius-30 dfj-flex dfj-flex-ai-c dfj-pd-lr-20 dfj-t-666" style="height: 60rpx;">
				<view><text class="dfj-icon icon-search"></text></view>
				<view class="dfj-flex-1 dfj-mg-l-20"><input v-model="searchTxt" class="" placeholder="请输入查询"/></view>
			</view>
		</uni-nav-bar>
		
		<view class="dfj-pd-30">
			<block v-for="(item,index) in searchList">
				<uni-tag :text="item" style="border: 1rpx solid #E5E5E5;display: inline-block;margin-right: 20rpx;" inverted="true" circle="true" @click="bindClick(item)"></uni-tag>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchTxt: '',
				searchList: []
			}
		},
		onLoad() {
			this.getSearchList()
		},
		methods:{
			leftBack() {
				uni.navigateBack();
			},
			getSearchList() {
				this.searchList = JSON.parse(localStorage.getItem('search')) || []
			},
			rightSearch() {
				let search = JSON.parse(localStorage.getItem('search'))
				if(search == null){
					let arr = []
					arr.push(this.searchTxt)
					localStorage.setItem('search', JSON.stringify(arr))
				}else{
					search.push(this.searchTxt)
					localStorage.setItem('search', JSON.stringify(search))
				}
				this.getSearchList()
				uni.navigateTo({
					url: `/pages/home/search-main?retrievalName=${this.searchTxt}`
				})
			},
			bindClick(txt) {
				uni.navigateTo({
					url: `/pages/home/search-main?retrievalName=${txt}`
				})
			}
		}
	}
</script>

<style>
</style>
